﻿@using KPIS.GERP.Models.ICM

@model PrePurchaseRequest
 
@{
    var MasterService = new KPIS.GERP.WEB.GIMS.IcmMasterService.IcmMasterServiceClient();
    var LookUpService = new KPIS.GERP.WEB.GIMS.IcmMasLookUpService.IcmMasLookUpServiceClient();
    var SysService = new KPIS.GERP.WEB.GIMS.SysMasterService.SysMasterServiceClient();

    var pcTypeSelectList = MasterService.SelectListPurchaseType(new MasPurchaseType { RecordStatus = "U" }, true);
    var prioritySelectList = LookUpService.MasLookUpSelectList(KPIS.GERP.Models.ICM.IcmMasLookUpType.LookUpType.Priority);
    var jobSiteSelectList = new KPIS.GERP.WEB.GIMS.JobsiteService.JobsiteServiceClient().LoadInternalJobSiteSelectList(GimsMembership.User.Employee.WorkingJobSiteId, true, 3);
    
    
    var yearTypeSelectList = SysService.SelectListYearType(null);
    var yearSelectList = SysService.SelectListGenerateRangeYear(15, 15, false);
    var durTypeSelectList = LookUpService.MasLookUpSelectList(KPIS.GERP.Models.ICM.IcmMasLookUpType.LookUpType.DurationType);
    var durCountSelectList = LookUpService.MasLookUpSelectList(KPIS.GERP.Models.ICM.IcmMasLookUpType.LookUpType.DurationCount);
}

@if (ViewContext.RouteData.Values["action"].ToString().ToLower() == "edit") { @Html.HiddenFor(model => model.PprId) }
@Html.HiddenFor(model => model.RequestEmpId)
@Html.HiddenFor(model => model.Code)
@Html.HiddenFor(model => model.ProgressId)
@Html.HiddenFor(model => model.RecordStatus)
@Html.HiddenFor(model => model.CreatedBy)
@Html.HiddenFor(model => model.CreatedWhen)
@Html.HiddenFor(model => model.CommitteeGroupId)
@Html.HiddenFor(model => model.UpdatedBy)
@Html.HiddenFor(model => model.UpdatedWhen)

<div class="widget-box" >
	<div class="widget-header header-color-blue2">
		<h4 class="lighter smaller">ข้อมูลหลัก</h4>
	</div>
	<div class="widget-body">
		<div class="widget-body-inner">
			<div class="widget-main">
                @if (Model != null && !string.IsNullOrWhiteSpace(Model.Code))
                {
                    <div class="control-group">
                        <div class="control-label">
                            เลขแจ้งความประสงค์
                        </div>
                        <div class="controls" style="font-weight: bold; ">
                            @Model.Code&nbsp;
                        </div>
                    </div>
                }
				<div class="control-group">
					<div class="control-label">
						@Html.DisplayNameFor(model => model.MasPurchaseType.PcTypeName)
					</div>
					<div class="controls">
						@Html.DropDownListFor(m => m.PcTypeId, pcTypeSelectList, new Dictionary<string, object>{{"class","chzn-select"}, {"data-placeholder", "เลือกประเภทการจัดหา"}})
						
						@Html.ValidationMessageFor(model => model.PcTypeId)
					</div>            
				</div>

				<div class="control-group">
					<div class="control-label">
						@Resources.GenerallyLocalization.Priority
					</div>
					<div class="controls">
						@{ int i = 0; }
						@foreach (var prioritySl in prioritySelectList)
						{ 
							<label style="float: left">
								<input name="PriorityId" type="radio" 
									value="@prioritySl.Value" 
									@((i == 0 && Model == null) || (Model != null && prioritySl.Value == Model.PriorityId.ToString())? 
										"checked=\"checked\"" : string.Empty)/>
								<span class="lbl"> @prioritySl.Text </span> &nbsp;&nbsp;&nbsp;
							</label>
							i++;
						}
						 
						@Html.ValidationMessageFor(model => model.PriorityId)
					</div>            
				</div>
				<hr />
				
				<div class="control-group">
					<div class="control-label">
						@Html.DisplayNameFor(model => model.RequestJobSite.Name)
					</div>
					<div class="controls">
						@Html.DropDownListFor(m => m.RequestJobSiteId, jobSiteSelectList
                            , new Dictionary<string, object>{{"class","chzn-select"}, {"data-placeholder", "เลือกหน่วยงาน"}})
						 
						@Html.ValidationMessageFor(model => model.RequestJobSiteId)
					</div>            
				</div>
                
                @Html.HiddenFor(model=>model.YearTypeId)
                @*
                <div class="control-group">
					<div class="control-label">
						@Html.DisplayNameFor(model => model.YearType.YearTypeName)
					</div>
					<div class="controls">
						@{ i = 0; }
						@foreach (var data in yearTypeSelectList)
						{ 
							<label style="float: left">
								<input name="YearTypeId" type="radio" value="@data.Value" 
									@((i == 0 && Model == null) || (Model != null &&
										KPIS.GERP.Models.Class.CompareUtility.IsObjectToStringEqual(data.Value, Model.YearTypeId)) ? 
                                        "checked=\"checked\"" : string.Empty) />
								<span class="lbl"> @data.Text </span>&nbsp;&nbsp;&nbsp;
							</label>
							i++;
						}

						@Html.ValidationMessageFor(model => model.YearTypeId)
					</div>            
				</div>
                *@
				
				<div class="control-group">
					<div class="control-label">
						@Html.DisplayNameFor(model => model.BgYear)
					</div>
					<div class="controls">
						@{
							var currentYear = yearSelectList.FirstOrDefault(o => KPIS.GERP.Models.Class.CompareUtility.IsObjectToStringEqual(
                                o.Value, KPIS.GERP.Models.Class.Utility.BuddishYear));
							if(currentYear != null ) { currentYear.Selected = true; }
						}
						@Html.TextBoxFor(m => m.BgYear, new { @class="input-mini", data_placeholder = "เลือกปีงบประมาณ", @readonly = true })
						@Html.ValidationMessageFor(model => model.BgYear)
					</div>            
				</div>
				
				<div class="control-group">
					<div class="control-label">
                        วันที่ทำรายการ
						@*@Html.DisplayNameFor(model => model.RequestDate)*@
					</div>
                    <div class="controls">
                        @{
                            DateTime? d = Model == null || Model.RequestDate == DateTime.MinValue ? (DateTime?)null : (DateTime?)Model.RequestDate;
                            // Resolve problem NaN/NaN/NaN show when initial screen
                        }
                        @Html.Editor("RequestDate2", "DateTime", new {placeholder = "วันที่ทำรายการ", value = d} )
                        @Html.ValidationMessageFor(model => model.RequestDate)
                    </div>            
				</div>
				
				<div class="control-group">
					<div class="control-label">
						@Html.DisplayNameFor(model => model.Name)
					</div>
					<div class="controls">
						@Html.TextBoxFor(model => model.Name, new {placeholder = "ใส่ชื่อเรื่อง"})
						@Html.ValidationMessageFor(model => model.Name)
					</div>            
				</div>

				<div class="control-group">
					<div class="control-label">
						@Html.DisplayNameFor(model => model.Reason)
					</div>
                    <div class="controls">
                        @Html.TextArea("Reason", new {rows=10, @class="span6", placeholder = "ใส่เหตุผลของการจัดหา"})
                        @*@Html.TextAreaFor(model => model.Reason, 
                                          new Dictionary<string, object>
                                              {
                                                  {"placeholder", "ใส่เหตุผลของการจัดหา"}, 
                                                  {"class", "autosize"}
                                              })*@
                        @Html.ValidationMessageFor(model => model.Reason)
                    </div>            
				</div> 
				
				<div class="control-group">
					<div class="control-label">
						@Resources.GenerallyLocalization.RequireDateFinished
					</div>
					<div class="controls"> 
						@{
							var durType10 = durTypeSelectList.FirstOrDefault(o => o.Value == "10");
							var durType11 = durTypeSelectList.FirstOrDefault(o => o.Value == "11");
						}
						<div id="durType1">
							<label style="float:left">
								<input name="DurTypeId" id="durType1radio" type="radio" value="10" @(Model == null || (Model != null && Model.DurTypeId == 10) ? "checked=\"checked\"" : "")/>
								<span class="lbl"> @(durType10 != null ? durType10.Text : string.Empty) </span>&nbsp;&nbsp;&nbsp;
							</label>
                            @Html.TextBoxFor(m=>m.RequireDuration, new {@class="input-mini", data_placeholder = "เลือกปีงบประมาณ"}) 
                            <span class="lbl">วัน นับจาก</span>
							@Html.DropDownListFor(m=>m.DurCountId, durCountSelectList, new {style="width:200px"})
						</div>
						<div id="durType2" style="margin-top: 5px">
							<label style="float:left">
								<input name="DurTypeId" id="durType2radio" type="radio" value="11" @(Model != null && Model.DurTypeId == 11 ? "checked=\"checked\"" : "")/>
								<span class="lbl"> @(durType11 != null ? durType11.Text : string.Empty) </span>&nbsp;&nbsp;&nbsp;
							</label>
							@Html.EditorFor(m=>m.RequireDate, new {PercentWidth="100"})
                        </div>  
                        
						@Html.ValidationMessageFor(model => model.DurTypeId)
						@Html.ValidationMessageFor(model => model.RequireDuration)
						@Html.ValidationMessageFor(model => model.DurCountId)
						@Html.ValidationMessageFor(model => model.RequireDate)
                    </div>
				</div>
			</div>
		</div>
	</div>
</div>